#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
using namespace std;
class Solution
{
public:
    int binsearch(vector<int> &arr, int target)
    {
        int l = 0, r = arr.size() - 1, mid;
        while (l <= r)
        {
            mid = (l + r) / 2;
            if (arr[mid] > target)
            {
                r = mid - 1;
            }
            else if (arr[mid] < target)
            {
                l = mid + 1;
            }
            else
                break;
        };
        if (l <= r)
            return mid;
        else
            return -1;
    }
    bool findNumberIn2DArray(vector<vector<int>> &matrix, int target)
    {
        bool flag = false;
        for (int i = 0; (i < matrix.size()) && (matrix[i].size() > 0) && flag == false; ++i)
        {
            if (matrix[i][0] <= target)
            {
                flag = (binsearch(matrix[i], target) != -1);
            }
        }
        return flag;
    }
};